<template>
  <view>
    <view class="hrader">
      <image
        src="../../../static/bback.png"
        class="goback"
        @click="back"
        mode=""
      />
      关注的人
    </view>
    <view class="" style="padding-top: 108rpx">
      <view class="user" v-for="(item, index) in userList" :key="index">
        <image :src="item.user_avatar" mode="" class="qifu"></image>
        <view class="xinwen">{{ item.user_nickname }}</view>
        <view class="yguanzhu" @click="openPop(item.id)" v-show="yfollow"
          >取消关注</view
        >
        <view
          class="guanzhu"
          @click="Confirmconcerns(item.care_user_id)"
          v-show="follow"
          >+关注</view
        >
      </view>
    </view>
    <view class="friends" v-show="show">
      <image
        class="img"
        src="../../../static/PersonalCenter/gzicon.png"
        mode=""
      />
      <text>您暂时还没有关注的人哦~</text>
    </view>
    <!-- 取消关注弹窗 -->
    <uni-popup ref="popup" type="center">
      <view class="popCenter">
        <view class="tips">温馨提示</view>
        <text style="padding: 40rpx 0">您确定要取消关注吗？</text>
        <view class="popBtn">
          <text class="cancel" @click="showClcik">取消</text>
          <text
            class="cancel"
            @click="quitClcik"
            style="border: 0; color: #c52b2e"
            >确定</text
          >
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      token: "",
      userList: [],
      yfollow: true,
      follow: false,
      show: false,
      id: "",
    };
  },
  onLoad() {
    this.token = uni.getStorageSync("token");
  },
  onShow() {
    this.getCareList();
  },

  methods: {
    back() {
      uni.switchTab({
        url: "../users",
      });
    },

    // 取消关注
    async openPop(id) {
      this.id = id;
      this.$refs.popup.open();
    },
    // 取消关注
    async quitClcik() {
      let that = this;
      const res = await that.$myRequest({
        url: "user/delCare",
        method: "POST",
        data: {
          id: this.id,
        },
      });
      if (res.data.code == 1) {
        this.$refs.popup.close();
        that.getCareList();
      }
    },
    showClcik() {
      this.$refs.popup.close();
    },
    async getCareList() {
      let that = this;

      const res = await that.$myRequest({
        url: "user/getCare",
        method: "POST",
        header: {
          token: that.token,
        },
      });

      if (res.data.code == 1) {
        that.userList = res.data.data.data;
        if (that.userList.length == 0) {
          this.show = true;
        }
      }
    },
  },
};
</script>

<style lang="scss">
.hrader {
  width: 100%;
  height: 88rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  position: relative;
  font-size: 36rpx;
  font-weight: 500;
  color: #333333;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 99;
  border-bottom: 20rpx solid #eee;
  .goback {
    position: absolute;
    width: 22rpx;
    height: 34rpx;
    left: 28rpx;
  }
  .reco {
    position: absolute;
    font-size: 30rpx;
    font-weight: 400;
    color: #333333;
    right: 30rpx;
  }
}
.user {
  width: 702rpx;
  height: 150rpx;
  box-sizing: border-box;
  border-bottom: 1rpx solid #eee;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .qifu {
    width: 90rpx;
    height: 90rpx;
    border-radius: 50%;
    margin-right: 25rpx;
  }
  .xinwen {
    font-size: 30rpx;
    font-weight: 500;
    color: #333333;
    flex: 1;
  }
  .yguanzhu {
    width: 142rpx;
    height: 54rpx;
    border: 1px solid #c52b2e;
    border-radius: 27rpx;
    font-size: 26rpx;
    text-align: center;
    line-height: 54rpx;
    font-weight: 400;
    color: #c52b2e;
  }
  .guanzhu {
    width: 142rpx;
    height: 54rpx;
    background-color: #c52b2e;
    font-size: 26rpx;
    border-radius: 27rpx;
    text-align: center;
    line-height: 54rpx;
    color: #ffffff;
  }
}
.user:last-child {
  border-bottom: none;
}
.friends {
  .img {
    display: block;
    width: 348rpx;
    height: 190rpx;
    margin: 314rpx auto 0;
  }
  text {
    display: block;
    text-align: center;
    font-size: 30rpx;
    font-weight: 400;
    color: #999999;
    margin: 20rpx auto 0;
  }
}
.popCenter {
  display: flex;
  align-items: center;
  flex-direction: column;
  width: 546rpx;
  padding: 40rpx 0 0;
  background-color: #fff;
  font-size: 30rpx;
  color: #333333;
  border-radius: 10rpx;
  .tips {
    text-align: center;
    font-size: 30rpx;
    font-weight: 550;
    color: #373737;
  }
  .popBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100rpx;
    border-top: 1rpx solid #eee;
    border-radius: 0 0 10rpx 10rpx;

    .cancel {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 28rpx;
      color: #373737;
      width: 50%;
      height: 100%;
      border-right: 1rpx solid #eee;
      letter-spacing: 2rpx;
    }
  }
}
</style>
